home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Source / 50-CommHardware / t1 / t1-config.frm.z / t1-config.frm
Encoding:
Text File  |  1997-07-30  |  10.2 KB  |  410 lines

  1. #!/usr/bin/perl5
  2. #
  3. # t1.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: t1-config.frm,v 1.31 1997/06/19 22:26:40 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23. require "/usr/OnRamp/lib/java.pm";
  24.  
  25. $confW = "/etc/config/wsyncd.options";
  26. $dummy = "/etc/config/wsyncd.options.tmp";
  27. $confDev = "/etc/uucp/Devices";
  28. $confSys = "/etc/uucp/Systems";
  29.  
  30. $myname = "t1-config.cgi";
  31. $title = "T1 Configuration";
  32.  
  33. $js = 
  34. "$js_standard
  35. $js_error_box
  36. $js_hostname
  37. function checkForm(form) {
  38.     if (!testHostname(form.nme, form.nme.value, \"connection name\", 0)) return (false);
  39.     return (true);
  40. }";
  41.  
  42. print "Content-type: text/html\n\n";
  43.  
  44. &get_fields;
  45.  
  46. &getCurrentStatus;
  47.  
  48. $help = $document_root . $ENV{"SCRIPT_NAME"};
  49. $help =~ s/cgi$/hlp/;
  50. exec $help if ($fld{'help'} eq "Help");
  51.  
  52. if ($fld{'doit'} eq 'Ok') {
  53.     if ($fld{'enable'} eq 'Yes') { &formValidation; }
  54.     if ($fld{'port'} eq 'Port 1') { 
  55.     $portOn = 0;
  56.     $portOff = 1; 
  57.     }
  58.     else { 
  59.     $portOn = 1;
  60.     $portOff = 0; 
  61.     }
  62.  
  63.     if ($fld{'enable'} eq 'Yes') { 
  64.         &turnOnPort($portOn);
  65.         &turnOffPort($portOff);
  66.     system("/etc/chkconfig", "wsyncd", "on");
  67.         system("/etc/init.d/wsync stop > /dev/null 2>&1");
  68.         system("/etc/init.d/wsync start > /dev/null 2>&1");
  69.         &handleSystems;
  70.         &handleDevices($portOn);
  71.         $message = "$fld{'port'} enabled."; 
  72.     } else {
  73.         &turnOffPort(0);
  74.         &turnOffPort(1);
  75.     system("/etc/chkconfig", "wsyncd", "off");
  76.         system("/etc/init.d/wsync stop > /dev/null 2>&1");
  77.         $message = "T1 disabled";
  78.     }
  79.     if (!$message) { $message = "No change."; }
  80.  
  81.     &getCurrentStatus;
  82. } elsif ($fld{'port'}) { $message = qq|Use "Ok" button to submit form.|; }
  83.  
  84. &generic;
  85.  
  86. sub formValidation {
  87.     &error("Invalid host name.") if &check_login($fld{'nme'});
  88. }
  89.  
  90. sub error {
  91.     &error_block($_[0]);
  92.     &generic;
  93.     exit 0;
  94. }
  95.  
  96. sub handleDevices {
  97.     $rename = 0;
  98.     $found = 0;
  99.     $dname = "/dev/gsc/wsty0".$_[0];
  100.     open(IN,"< $confDev");
  101.     open(OUT,"> $dummy");
  102.     while(<IN>) {
  103.     @items = split(/\s+/);
  104.     if ($items[0] ne 'WAN') { print OUT $_; next; }
  105.     if ($items[1] ne $dname) {
  106.         print OUT "# $_";
  107.         $rename = 1;
  108.         $found = 1;
  109.         print OUT qq|WAN $dname - - direct\n|;
  110.     } else { print OUT $_; $found = 1; }
  111.     }
  112.     if (!$found) {
  113.     print OUT qq|WAN $dname - - direct\n|;
  114.     $rename = 1;
  115.     }
  116.     close(IN);
  117.     close(OUT);
  118.     if ($rename) { rename($dummy,$confDev); }
  119. }    
  120.     
  121.  
  122. sub handleSystems {
  123.     $rename = 0;
  124.     $found = 0;
  125.     open(IN,"< $confSys");
  126.     open(OUT,"> $dummy");
  127.     while(<IN>) {
  128.     @items = split(/\s+/);
  129.     if ($items[2] ne 'WAN') { print OUT $_; next; }
  130.     if ($items[0] ne $fld{'nme'}) {
  131.         print OUT "# $_";
  132.         $rename = 1;
  133.         $found = 1;
  134.         print OUT qq|$fld{'nme'} Any WAN - "" "" PPP CONNECTED\n|;
  135.     } else { print OUT $_; $found = 1; }
  136.     }
  137.     if (!$found) {
  138.     print OUT qq|$fld{'nme'} Any WAN - "" "" PPP CONNECTED\n|;
  139.     $rename = 1;
  140.     }
  141.     close(IN);
  142.     close(OUT);
  143.     chmod 600, $confSys;
  144.     if ($rename) { rename($dummy,$confSys); }
  145.     chmod 400, $confSys;
  146. }    
  147.  
  148. sub turnOffPort {
  149.     $nm = $_[0];
  150.  
  151.     undef @terms;
  152.     $terms[0] = 'wan0'.$nm;
  153.     if (&lookFor(0,$confW,*terms)) { &comment($confW,*terms); }
  154.  
  155.     $terms[0] = 'wstyd0'.$nm;
  156.     if (&lookFor(0,$confW,*terms)) { &comment($confW,*terms); }
  157.  
  158.     $terms[0] = 'wstyd0'.$nm;
  159.     $terms[1] = 'wan0'.$nm;
  160.     if (&lookFor(0,$confW,*terms)) { &comment($confW,*terms); }
  161. }
  162.  
  163. sub turnOnPort {
  164.     $nm = $_[0];
  165.  
  166.     undef @terms;
  167.     $terms[0] = 'wan0'.$nm;
  168.     if (&lookFor(1,$confW,*terms)) { &uncomment($confW,*terms); }
  169.     elsif (! &lookFor(0,$confW,*terms)) { 
  170.     &writeTop($confW,"wan0".$nm."\td\t\t/dev/gsc/wan0".$nm); 
  171.     }
  172.  
  173.     $terms[0] = 'wstyd0'.$nm;
  174.     if (&lookFor(1,$confW,*terms)) { &uncomment($confW,*terms); }
  175.     elsif (! &lookFor(0,$confW,*terms)) { 
  176.     &writeTop($confW,"wstyd0".$nm."\t\td\t/dev/gsc/wstyd0".$nm); 
  177.     }
  178.  
  179.     $terms[0] = 'wstyd0'.$nm;
  180.     $terms[1] = 'wan0'.$nm;
  181.     if (&lookFor(1,$confW,*terms)) { 
  182.     &uncomment($confW,*terms); }
  183.     elsif (! &lookFor(0,$confW,*terms)) {
  184.     if ($nm == 0) { $let = "D"; } else { $let = "E"; }
  185.     &writeBottom($confW,"$terms[0]\t\t$terms[1]\tWSYNCD_SNID=$let"); 
  186.     }
  187. }
  188.  
  189. sub writeTop {
  190.     local($file) = $_[0];
  191.     local($value) = $_[1];
  192.     $found = 0;
  193.     open(IN,"< $file");
  194.     open(OUT,"> $dummy");
  195.     while(<IN>) {
  196.     if ($_ eq "%%\n" && $found == 0) {
  197.         $found = 1;
  198.         print OUT "$value\n\n%%\n";
  199.     }
  200.     if ($_ eq "\n" && $found == 0) {
  201.         $found = 1; 
  202.         print OUT "\n$value\n";
  203.     } else { print OUT $_; }
  204.     }
  205.     close(IN);
  206.     close(OUT);
  207.     rename($dummy,$file);
  208. }            
  209.  
  210. sub writeBottom {
  211.     local($file) = $_[0];
  212.     local($value) = $_[1];
  213.     $found = 0;
  214.     open(IN,"< $file");
  215.     open(OUT,"> $dummy");
  216.     while(<IN>) {
  217.     if (substr($_,0,2) eq '%%' && $found == 0) {
  218.         print OUT "%%\n\n$value\n";
  219.         $found = 1;
  220.     } else { print OUT $_; }
  221.     }
  222.     if ($found == 0) { print OUT "$value\n"; }
  223.     close(IN);
  224.     close(OUT);
  225.     rename($dummy,$file);
  226. }
  227.    
  228. sub uncomment {
  229.     local($file) = $_[0];
  230.     local(*values) = @_[1];
  231.     open(IN,"< $file");
  232.     open(OUT,"> $dummy");
  233.     $fix = "fix";
  234.  
  235.     while(<IN>) {
  236.     $line = $_;
  237.     if ($line eq "\n") { print OUT "\n"; next; }
  238.     $fix =~ /(fix)/;
  239.     $line =~ /^\s*\#\s*(\S.*)/;
  240.     $line1 = $1;
  241.     @items = split(/\s+/,$line1);
  242.     $chk = 1;
  243.     for ($ii=0;$ii<=$#values;$ii++) {
  244.         if ($items[$ii] ne $values[$ii]) { $chk = 0; }
  245.     }
  246.     if ($chk) { print OUT "$line1\n"; }
  247.     else { print OUT $line; }
  248.     }
  249.     close(OUT);
  250.     close(IN);
  251.     rename($dummy,$file);
  252. }
  253.  
  254. sub comment {    
  255.     local($file) = $_[0];
  256.     local(*values) = @_[1];
  257.     open(IN,"< $file");
  258.     open(OUT,"> $dummy");
  259.     while(<IN>) {
  260.     $line = $_;
  261.     if ($line eq "\n") { print OUT "\n"; next; }
  262.     @items = split(/\s+/,$line);
  263.     $chk = 1;
  264.     for ($ii=0;$ii<=$#values;$ii++) {
  265.         if ($items[$ii] ne $values[$ii]) { $chk = 0; }
  266.     }
  267.     if ($chk) { print OUT "#$line"; }
  268.     else { print OUT $line; }
  269.     }
  270.     close(OUT);
  271.     close(IN);
  272.     rename($dummy,$file);
  273. }
  274.  
  275. sub lookFor {
  276.     local($ii);
  277.     local($mode) = $_[0];
  278.     local($file) = $_[1];
  279.     local(*values) = @_[2];
  280.     open(IN,"< $file");
  281.     while(<IN>) {
  282.     $line = $_;
  283.     if ($mode == 1) {
  284.         $line =~ /^\s*\#\s*(\S.*)/;
  285.         $line1 = $1;
  286.     } else { $line1 = $line; }
  287.     @items = split(/\s+/,$line1);
  288.     $chk = 1;
  289.     for ($ii=0;$ii<=$#values;$ii++) {
  290.         if ($items[$ii] ne $values[$ii]) { $chk = 0; }
  291.     }
  292.     if ($chk) { close(IN); return 1; }
  293.     }
  294.     close(IN);
  295.     return 0;
  296. }
  297.  
  298. # will check for existence of correct, uncommented lines.  does 
  299. # not check for conflicts with other devices (yet)
  300. # Also checks chkconfig status of wsyncd.
  301. sub getCurrentStatus {
  302.         $wsyncd = "/usr/etc/wsyncd";
  303.  
  304.         if (! -e $wsyncd || !&isT1Board) {
  305.             &title_block($title);
  306.             &header_block($title);
  307.             if (! -e $wsyncd) { 
  308.             $message = "T1 software not installed.  Install subsystems "
  309.                 . "</i><b>wsync.sw.sw</b><i> and </i><b>eoe.sw.dlpi</b><i> "
  310.                 . "from the T1 software CD.</i>"; 
  311.         } else { $message = "T1 hardware not installed."; }
  312.             print "<i>$message</i>";
  313.             exit 0;
  314.         }
  315.  
  316.     $port = "Port 1";
  317.     $enable = 'No';
  318.     for ($i=0;$i<2;$i++) {
  319.     $chw[$i] = &checkWsyncd($i);
  320.     if ($chw[$i]) { 
  321.         $enable = 'Yes';
  322.         if ($i) { $port = "Port 2"; } 
  323.     }
  324. #    else { $enable = 'No'; }
  325.     }
  326.     $ch_opt = &get_config("wsyncd");
  327.     if ($ch_opt eq "No") { $enable = "No"; }
  328.  
  329.     $nme = "";
  330.     open(IN,"< $confSys");
  331.     while(<IN>) {
  332.     @items = split(/\s+/);
  333.     if ($items[2] eq 'WAN') { $nme = $items[0]; }
  334.     }
  335.     close(IN);
  336. }
  337.  
  338. sub isT1Board {
  339.     $ret = 0;
  340.     open(IN,"/usr/bin/hinv | ");
  341.     while(<IN>) {
  342.     @items = split(/\s+/);
  343.     if ($items[0] eq 'GIO') { 
  344.         $ret = 1;
  345.         $last;
  346.     }
  347.     }
  348.     close(IN);
  349.     return $ret;
  350. }
  351.  
  352. # here only check that the line is uncommented
  353. sub checkWsyncd {
  354.     $nm = $_[0];
  355.     $beforePercent = 1;
  356.     $check1 = 0;
  357.     $check2 = 0;
  358.  
  359.     open(IN,"< $confW");
  360.     while(<IN>) {
  361.     $line = $_;
  362.     if (substr($line,0,1) eq '#') { next; }
  363.     if ($line eq "%%\n") {
  364.         if ($check1 == 0 || $check2 == 0) { return 0; }
  365.         $beforePercent = 0; next; }
  366.     @items = split(/\s+/,$line);
  367.  
  368.     if ($beforePercent && $items[0] eq "wan0".$nm) { $check1 = 1; }
  369.     if ($beforePercent && $items[0] eq "wstyd0".$nm) { $check2 = 1; }
  370.     if (!$beforePercent && $items[0] eq 'wstyd0'.$nm) { return 1; }
  371.     }
  372.     close(IN);
  373.     return 0;
  374. }
  375.     
  376. sub generic {
  377.     &js_title_block($title,$js);
  378.     &header_block($title);
  379.  
  380.     print "<form name=StandardForm action=$myname method=post onSubmit=\"return runSubmit()\">";
  381.  
  382.     print "<i>$message</i>";
  383.  
  384.     print "<center><table cellpadding=5 width=450>";
  385.  
  386. #    print "<tr><th></th><th align=left>Port 1</th><th align=left>Port 2</th></tr>";
  387.  
  388. #    print "<tr><th align=left>Enable T1:</th><th align=left>",
  389. #      &radio('enable0',$enable[0],'Yes','No'),
  390. #      "</th><th align=left>",
  391. #      &radio('enable1',$enable[1],'Yes','No'),
  392. #      "</th></tr>";
  393.  
  394.     print qq|<tr><th align=left>Enable T1:</th><th align=left>|,
  395.         &radio("enable",$enable,"Yes","No"),"</th></tr>";
  396.  
  397.     print "<tr><th align=left>Port:</th><th align=left>",
  398.         &radio('port',$port,'Port 1','Port 2'),"</th></tr>";
  399.  
  400.     print "<tr><th align=left>Connection name for remote system:</th>
  401.         <th align=left>",
  402.         &text('nme',$nme,12),"</th></tr>";
  403.  
  404.     print '</table></center><br>';
  405.  
  406.     print &js_buttons('doit','Ok','onClick="markOK()"','onClick="markOther()"');
  407.  
  408.     print '</form></body></html>';
  409. }
  410.